import sqlite3
from pathlib import Path

DB_PATH = Path(__file__).resolve().parents[1] / "n8ncrm.db"

def main():
    conn = sqlite3.connect(str(DB_PATH))
    cur = conn.cursor()

    cur.execute('SELECT name FROM sqlite_master WHERE type="table" ORDER BY name')
    tables = [r[0] for r in cur.fetchall()]
    print("tables=", tables)

    # Users overview
    if "users" in tables:
        cur.execute('SELECT id,email,full_name,hashed_password,is_active FROM users')
        rows = cur.fetchall()
        print("users_count=", len(rows))
        if rows:
            first = rows[0]
            hp = first[3]
            print("first_user=", first)
            print("hashed_prefix=", hp[:7] if isinstance(hp, str) else None)

    # Audit log table info
    if "auditlog" in tables:
        cur.execute('PRAGMA table_info(auditlog)')
        print("auditlog_cols=", cur.fetchall())
    else:
        print("auditlog table missing")

    conn.close()

if __name__ == "__main__":
    main()